﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ClientMobile.SSVService;
using googlemaps;

namespace ClientMobile
{
    public partial class Mission_attente : PhoneApplicationPage
    {
        public Mission_attente()
        {
            InitializeComponent();
            Singleton s = Singleton.Instance;
            Service1SoapClient ser = new Service1SoapClient();
            //ser.ConsulterMissionchCompleted += new EventHandler<ConsulterMissionchCompletedEventArgs>(ser_ConsulterMissionchCompleted);
            //ser.ConsulterMissionchAsync(s.Chauff.id_chauffeur);
            
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string bb;
            if (NavigationContext.QueryString.TryGetValue("miss", out bb))
                {
                    Service1SoapClient ser = new Service1SoapClient();
                ser.ConsulterMissionCompleted+=new EventHandler<ConsulterMissionCompletedEventArgs>(ser_ConsulterMissionCompleted);
                ser.ConsulterMissionAsync(Convert.ToInt16(bb));
                }
        }
        void ser_ConsulterMissionCompleted(object sender, ConsulterMissionCompletedEventArgs e)
        {

            textddecl.Text = e.Result.DateDeclanchement.ToString();
            textdfinest.Text = e.Result.DateFinEstimé.ToString();
            textmiss.Text = e.Result.libellé;
            textetat.Text = e.Result.Etat;
            textmiss.Text = e.Result.libellé;
            textroute.Text = e.Result.id_route.ToString();
            textveh.Text = e.Result.id_vehicule.ToString();
        }
        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            //à regler le id ds le singleton
            Singleton s = Singleton.Instance;
            Service1SoapClient ser = new Service1SoapClient();
            ser.Declancher_MissionCompleted += new EventHandler<Declancher_MissionCompletedEventArgs>(ser_Declancher_MissionCompleted);
            ser.Declancher_MissionAsync(1);
        }

        void ser_Declancher_MissionCompleted(object sender, Declancher_MissionCompletedEventArgs e)
        {
             if (e.Result != false)
            {
                MessageBox.Show("mission déclenchée!");
                NavigationService.Navigate(new Uri("/m_enattente.xaml", UriKind.Relative));
            }
            else
            { MessageBox.Show("Erreur de déclenchement!!");}
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/m_enattente.xaml", UriKind.Relative));
        }
            
        }
           
           
        

     
           


    }
